package com.tao.service.area;


import com.tao.dao.BaseAreaMapper;
import com.tao.pojo.BaseArea;
import com.tao.pojo.BaseAreaExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaServiceImpl implements IareaService {

	@Autowired
	BaseAreaMapper areaMapper;

	/**
	 * 获取全部区域
	 * @return
     */
	@Override
	public List<BaseArea> getArea() {
		BaseAreaExample areaExample=new BaseAreaExample();
		areaExample.createCriteria().andParentidEqualTo(0);
		List<BaseArea> list=areaMapper.selectByExample(areaExample);
		for (BaseArea baseArea : list) {
			BaseAreaExample childExample=new BaseAreaExample();
			childExample.createCriteria().andParentidEqualTo(baseArea.getCodeid());
			List<BaseArea> children=areaMapper.selectByExample(childExample);
			for (BaseArea baseArea2 : children) {
				BaseAreaExample childExample2=new BaseAreaExample();
				childExample2.createCriteria().andParentidEqualTo(baseArea2.getCodeid());
				baseArea2.setChildren(areaMapper.selectByExample(childExample2));
			}
			baseArea.setChildren(children);
		}
		return list;
	}

}
